-
Notifications
You must be signed in to change notification settings - Fork 87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add minimum length for responses to be gzipped #20
base: master
Are you sure you want to change the base?
Conversation
Very short responses become larger if they are gzipped. With the minLength parameter you can define what minimum length a response should have before it is gzipped. The response is buffered up to the minimum length. As soon as the length of the response becomes larger than the minimum length, the buffered part will be written to the gzip writer and the headers will be set accordingly. After that no more buffering will be applied. If the response stays shorter than the minimum length, it will stay uncompressed and no Accept-Encoding and Vary headers will be set.
Codecov Report
@@ Coverage Diff @@
## master #20 +/- ##
=======================================
- Coverage 90.24% 90% -0.25%
=======================================
Files 1 1
Lines 41 60 +19
=======================================
+ Hits 37 54 +17
- Misses 3 4 +1
- Partials 1 2 +1
Continue to review full report at Codecov.
|
@@ -39,7 +39,7 @@ import ( | |||
|
|||
func main() { | |||
r := gin.Default() | |||
r.Use(gzip.Gzip(gzip.DefaultCompression)) | |||
r.Use(gzip.Gzip(gzip.DefaultCompression, 0)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not part of the project but can you add this by using options pattern so it doesn't break all the existing code out there.
Very short responses become larger if they are gzipped. With
the minLength parameter you can define what minimum length a
response should have before it is gzipped. The response is
buffered up to the minimum length. As soon as the length of
the response becomes larger than the minimum length, the buffered
part will be written to the gzip writer and the headers will be
set accordingly. After that no more buffering will be applied.
If the response stays shorter than the minimum length, it will
stay uncompressed and no Accept-Encoding and Vary headers will
be set.